package com.systemframework.sys.controller;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.systemframework.annotation.LicenseAnnotation;
import com.systemframework.common.BaseCommonInterface;
import com.systemframework.sys.dto.request.SysLogRequestDTO;
import com.systemframework.sys.dto.response.SysLogResponseDTO;
import com.systemframework.sys.service.SysLogService;
import com.systemframework.util.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author summer
 * @date 2023-03-21 18:04
 */
@RestController
@RequestMapping(value = "/log")
@Slf4j
public class SysLogController implements BaseCommonInterface<SysLogRequestDTO, SysLogResponseDTO> {


    @Override
    public Result<String> save(@Valid SysLogRequestDTO sysLogRequestDTO) {
        return null;
    }

    @Override
    public Result<String> update(SysLogRequestDTO sysLogRequestDTO) {
        return null;
    }

    @Override
    public Result<String> del(Integer id) {
        sysLogService.removeById(id);
        return  Result.successResult();
    }

    @LicenseAnnotation
    @Override
    public Result<Page<SysLogResponseDTO>> lists(SysLogRequestDTO sysLogRequestDTO) {
        Page<SysLogResponseDTO> page= sysLogService.lists(sysLogRequestDTO);
        return Result.successResult(page);
    }

    private SysLogService sysLogService;

    @Autowired
    public void setSysLogService(SysLogService sysLogService) {
        this.sysLogService = sysLogService;
    }

    @Override
    public Result<SysLogResponseDTO> findById(Integer id) {
        return null;
    }


    @LicenseAnnotation
    @Override
    public Result<String> batchDel(List<SysLogResponseDTO>  lists){
        List<Integer> ids = lists.stream().map(SysLogResponseDTO::getId).collect(Collectors.toList());
        if(ids.size()>0 && CollUtil.isNotEmpty(ids)){
            sysLogService.removeByIds(ids);
        }
        return Result.successResult();
    }
}
